package net.jjjshop.common.mapper.order;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.jjjshop.common.entity.order.Order;

import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;


/**
 * 订单记录表 Mapper 接口
 *
 * @author jjjshop
 * @since 2022-07-04
 */
@Repository
public interface OrderMapper extends BaseMapper<Order> {


    @Select("SELECT  SUM(pay_price) FROM jjjshop_order WHERE pay_status = 20 and TO_DAYS(NOW()) - TO_DAYS( create_time) <= 1 ")
    Double getYesterdaySales();

    @Select("SELECT user_id,sum(pay_price) order_price from jjjshop_order WHERE pay_status =20 and user_id in (" +
            "SELECT user_id from jjjshop_user WHERE zt_order_num >=3" +
            ") and order_price>=3000 GROUP BY user_id")
    List<Order> getUserOrder();


    @Select("SELECT COALESCE(sum(pay_price),0) order_price from jjjshop_order WHERE pay_status =20  and order_price>3000 and user_id=#{userId}")
    BigDecimal getSumUserMoney(Integer userId);
}
